const db=require('../db/index')
exports.getSaveDetail=(req,res)=>{
    db.query('select username,hasMoney,savedetail.id,saveTypeId,savePlan,startTime,avgMoeny,money,increase,userId,saveTime,saveName from savetype,savedetail,users where (users.id=? or users.id=?) and savetype.id=savedetail.saveTypeId and savedetail.userId=users.id order by startTime desc',[req.user.id,req.user.associated_id],(err,result)=>{
        if(err){
            return req.resSend(401,err)
        }
        if(result.length===0){
            return req.resSend(404,'暂无存钱计划！')
        }
        res.send({
            status:200,
            msg:'存钱计划获取成功！',
            data:result
        })
    })
}

exports.getTypeSavingDetail=(req,res)=>{
     db.query('select username,hasMoney,savedetail.id,saveTypeId,savePlan,startTime,avgMoeny,money,increase,userId,saveTime,saveName from savetype,savedetail,users where (users.id=? or users.id=?) and savetype.id=savedetail.saveTypeId and savedetail.userId=users.id and saveTypeId=? order by startTime desc',[req.user.id,req.user.associated_id,req.query.id],(err,result)=>{
        if(err){
            return req.resSend(401,err)
        }
        if(result.length===0){
            return req.resSend(404,'暂无该类型的存钱记录！')
        }
        res.send({
            status:200,
            msg:'该类型存钱记录获取成功！',
            data:result
        })
     })
}